﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace weatherinfo
{
    public class Units
    {
        XmlNode m_xml;
        private string m_temp;
        private string m_distance;
        private string m_speed;
        private string m_pressure;
        private string m_precipitation;

        public Units()
        {
            init(false);
        }
        public Units(XmlNode unitsnode)
        {
            init(false);
            m_xml = unitsnode;
            LoadXml(m_xml);
        }
        private void init(bool metric)
        {
            m_xml = null;
            m_temp = metric ? "C" : "F";
            m_distance = metric ? "KM" : "MI";
            m_speed = metric ? "MPH" : "KPH";
            m_pressure = metric ? "kPa" : "IN";
            m_precipitation = metric ? "MM" : "IN";
        }
        public void LoadXml(XmlNode xml)
        {
            if (xml.Name != "units")
                return;
            for (int i = 0; i < xml.ChildNodes.Count; i++)
            {
                XmlNode node = xml.ChildNodes[i];
                if (node.Name == "temp")
                    m_temp = node.InnerText;
                else if (node.Name == "dist")
                    m_distance = node.InnerText;
                else if (node.Name == "speed")
                    m_speed = node.InnerText;
                else if (node.Name == "pres")
                    m_pressure = node.InnerText;
                else if (node.Name == "prec")
                    m_precipitation = node.InnerText; 
            }
        }

        public string Temperatue
        {
            get { return m_temp; }
            set { m_temp = value; }
        }
        public string Distance
        {
            get { return m_distance; }
            set { m_distance = value; }
        }
        public string Speed
        {
            get { return m_speed; }
            set { m_speed = value; }
        }
        public string Pressure
        {
            get { return m_pressure; }
            set { m_pressure = value; }
        }
        public string Precipitation
        {
            get { return m_precipitation; }
            set { m_precipitation = value; }
        }
    }
}
